
#ifndef B_xs_QUEUE_H__
#define B_xs_QUEUE_H__

#ifndef BOOL
#define BOOL int
#endif

#ifndef TRUE
#define TRUE 1
#endif 

#ifndef FALSE
#define FALSE 0
#endif

#ifdef __cplusplus
extern "C" {
#endif

#include "xs_linux.h"

typedef struct __xs_queue_item__ xs_queue_item;
typedef struct __xs_queue__ xs_queue;

struct __xs_queue_item__{
	void *data;
    	xs_queue_item *next;
};


struct __xs_queue__{

	xs_queue_item *head;
	xs_queue_item *tail;
	xs_pthread_mutex_t lock;

    	xs_queue_item *__freelist;
    	xs_pthread_mutex_t __freelist_lock;

	unsigned count;
};

xs_queue *xs_queue_create();
void xs_queue_destroy(xs_queue *cq);
void xs_queue_initilization(xs_queue *cq);
xs_queue_item *xs_queue_item_new(xs_queue *cq);
void xs_queue_item_free(xs_queue *cq, xs_queue_item *item);

xs_queue_item *xs_queue_head(xs_queue *cq);
xs_queue_item *xs_queue_tail(xs_queue *cq);
xs_queue_item *xs_queue_peek(xs_queue *cq);

xs_queue_item *xs_queue_dequeue(xs_queue *cq);
void *xs_queue_dequeue_data(xs_queue *cq);
void xs_queue_enqueue(xs_queue *cq, xs_queue_item *item);
int xs_queue_enqueue_data(xs_queue *cq, void *data);

unsigned xs_queue_count(xs_queue *cq);
BOOL xs_queue_is_empty(xs_queue *cq);

#ifdef __cplusplus
}
#endif

#endif
